package com.easy.generator.vue;

import com.easy.generator.Easy;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;

/**
 * @author easy
 * @date 2025年07月11日 14:45
 */
public class Package_Generator {
    private static final String DIR_NAME = Easy.VUE_LOCAL_PATH;
    private static final String FILE_NAME = "package.json";
    private static final String FILE_TEMPLATE =
            "{\n" +
                    "  \"name\": \""+Easy.VUE_PROJECT_NAME+"\",\n" +
                    "  \"version\": \"0.0.0\",\n" +
                    "  \"private\": true,\n" +
                    "  \"type\": \"module\",\n" +
                    "  \"scripts\": {\n" +
                    "    \"dev\": \"vite\",\n" +
                    "    \"build\": \"vite build\",\n" +
                    "    \"preview\": \"vite preview\"\n" +
                    "  },\n" +
                    "  \"dependencies\": {\n" +
                    "    \"@element-plus/icons-vue\": \"^2.3.1\",\n" +
                    "    \"axios\": \"^1.10.0\",\n" +
                    "    \"element-plus\": \"^2.10.3\",\n" +
                    "    \"lodash\": \"^4.17.21\",\n" +
                    "    \"pinia\": \"^3.0.3\",\n" +
                    "    \"vue\": \"^3.5.17\",\n" +
                    "    \"vue-router\": \"^4.5.1\"\n" +
                    "  },\n" +
                    "  \"devDependencies\": {\n" +
                    "    \"@vitejs/plugin-vue\": \"^6.0.0\",\n" +
                    "    \"vite\": \"^7.0.0\",\n" +
                    "    \"vite-plugin-vue-devtools\": \"^7.7.7\"\n" +
                    "  }\n" +
                    "}\n";

    public static void generate() throws IOException {
        String content = String.format(FILE_TEMPLATE, LocalDate.now());
        File outputFile = new File( DIR_NAME+ "/" + FILE_NAME);
        if (!outputFile.exists()) {
            outputFile.getParentFile().mkdirs();
            outputFile.createNewFile();
        }
        try (FileWriter writer = new FileWriter(outputFile)) {
            writer.write(content);
        }
        System.out.println("已生成文件：" + outputFile.getAbsolutePath());
    }
}
